package cst.neu.yuejian_31.model;

import cst.neu.yuejian_31.bean.RefundBean;
import cst.neu.yuejian_31.iface.RefundIface;
import cst.neu.yuejian_31.iface.RefundListener;
import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.service.RefundService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xxe on 2017/10/30.
 */

public class RefundModel implements RefundIface {
    private Retrofit retrofit;
    public RefundModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }
    @Override
    public void reFund(String orderId, final RefundListener refundListener) {
        RefundService refundService=retrofit.create(RefundService.class);
        Call<RefundBean>call=
                refundService.reFund(orderId);
        call.enqueue(new Callback<RefundBean>() {
            @Override
            public void onResponse(Call<RefundBean> call, Response<RefundBean> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    refundListener.onSuccess(response.body());
                }else {
                    refundListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<RefundBean> call, Throwable t) {
            refundListener.onFail(t.toString());
            }
        });

    }
}
